﻿using System;
using FlashCards.WebApplication.DAL;
using System.Data.SqlClient;
using System.Diagnostics;

namespace FlashCards.WebApplication.Maintenance
{
    public class Logger
    {
        public static void Log(string source, string description)
        {
            DateTime date = DateTime.Now;
            Log(date, source, description);
        }

        private static void Log(DateTime date, string source, string description)
        {
            using (SqlCommand cmd = new SqlCommand("InsertLog") { CommandType = System.Data.CommandType.StoredProcedure })
            {
                cmd.Parameters.Add("@Date", System.Data.SqlDbType.DateTime).Value = date.ToString(System.Globalization.CultureInfo.InvariantCulture);
                cmd.Parameters.Add("@Source", System.Data.SqlDbType.VarChar, 200).Value = source;
                cmd.Parameters.Add("@Description", System.Data.SqlDbType.VarChar, 300).Value = description;
                int affectedRows = DataBaseConnector.ExecuteNonQueryProcedure(cmd);
                Trace.TraceInformation("Logged new information. Numbers of rows affectd: {0}", affectedRows);
            }
        }
    }
}